package com.gz.EuchreU.Scene;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.handler.IUpdateHandler;

import com.gz.EuchreU.Contants.CardValues;
import com.gz.EuchreU.Contants.GameState;
import com.gz.EuchreU.Contants.Suits;
import com.gz.EuchreU.Contants.UI;
import com.gz.EuchreU.Controls.DifficultyMenu;
import com.gz.EuchreU.Controls.OptionsMenu;
import com.gz.EuchreU.Controls.RulesMenu;
import com.gz.EuchreU.Controls.UIButton;
import com.gz.EuchreU.Helpers.Textures;
import com.gz.EuchreU.Sprite.Card;
import com.gz.Game.Extension.GameScene;

public class OptionsScene extends GameScene {

	private boolean mLoaded = false;
	
	private UIButton btnRules;
	private UIButton btnOptions;
	private UIButton btnDifficulty;
	private OptionsMenu mOptions;
	private RulesMenu mRules;
	private DifficultyMenu mDifficulty;
	
	public OptionsScene(int pLayerCount, Engine baseEngine) {
		super(pLayerCount, baseEngine);
		// TODO Auto-generated constructor stub

		registerUpdateHandler(getUpdateHandler());
		setOnAreaTouchTraversalFrontToBack();
	}

	@Override
	protected void onLoadComplete() {
		
	}

	@Override
	protected void onLoadResources() {
		//Should already be loaded. 
	}

	@Override
	protected void onLoadScene() {
		
	}

	@Override
	protected void unloadScene() {
		
	}

	private void InitOptions(){
		
		mOptions = new OptionsMenu(UI.getWidth()/8,50,3*UI.getWidth()/4,this);
		mRules = new RulesMenu(UI.getWidth()/8,50,3*UI.getWidth()/4,this);
		mDifficulty = new DifficultyMenu(UI.getWidth()/8,50,3*UI.getWidth()/4,this);
		
		attachChild(mOptions);
		attachChild(mRules);
		attachChild(mDifficulty);
		
		float buffer = 10;
		float buttonX = buffer;
		float buttonW = (UI.getWidth() - 4*buffer)/3;
		
		btnOptions = new UIButton("Options",buttonX,buffer,buttonW,Textures.BUTTON_TEXTURE, this){

			@Override
			public boolean OnTouched() {
				ShowOptions();
				return true;
			}

			
		};
		
		buttonX += buttonW + buffer;
		
		btnRules = new UIButton("Rules",buttonX,buffer,buttonW,Textures.BUTTON_TEXTURE, this){

			@Override
			public boolean OnTouched() {
				ShowRules();
				return true;
			}

			
		};
		
		buttonX += buttonW + buffer;
		
		btnDifficulty = new UIButton("Difficulty",buttonX,buffer,buttonW,Textures.BUTTON_TEXTURE, this){


			@Override
			public boolean OnTouched() {
				ShowDifficulty();
				return true;
			}
			
		};
		
		getFirstChild().attachChild(btnOptions);
		getFirstChild().attachChild(btnRules);
		getFirstChild().attachChild(btnDifficulty);
		
		ShowOptions();
	}
	
	private void ShowOptions(){
		mOptions.Show();
		mRules.Hide();
		mDifficulty.Hide();
	}
	
	private void ShowRules(){
		mOptions.Hide();
		mRules.Show();
		mDifficulty.Hide();
	}

	private void ShowDifficulty(){
		mOptions.Hide();
		mRules.Hide();
		mDifficulty.Show();
	}
	
	private IUpdateHandler getUpdateHandler(){
		return new IUpdateHandler(){

			public void onUpdate(float pSecondsElapsed) {
				if(!mLoaded){
					mLoaded = true;
					InitOptions();
				}
			}

			public void reset() {
				// TODO Auto-generated method stub
				
			}
		};
	}

}
